<template>
  <div class="changeAddr">
    <el-form
      ref="addrform"
      :model="addrform"
      :rules="rulesaddr"
      label-width="100px"
      class="forms"
      :disabled="edit ? true : false"
    >
      <el-form-item label="收件人" prop="takeOverUser">
        <el-input
          placeholder="请输入收件人"
          v-model="addrform.takeOverUser"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="联系电话" prop="takeOverMobile">
        <el-input
          placeholder="请输入联系电话"
          v-model="addrform.takeOverMobile"
          type="text"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="收货地址" prop="takeOverAddress">
        <el-input
          placeholder="请输入收货地址"
          v-model="addrform.takeOverAddress"
          type="text"
          clearable
        ></el-input>
      </el-form-item>

      <el-form-item v-if="!edit ? true : false">
        <el-button plain  @click="cancel()"
          >取消</el-button
        >
        <el-button type="primary" @click="submitAddr('addrform')"
          >保存</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { invoicing } from "../../apis/index";
export default {
  props: ["infBox", "edit"],
  name: "changeAddr",
  components: {},
  data() {
    return {
      // 修改收货地址
      addrform: {
        takeOverUser: "",
        takeOverMobile: "",
        takeOverAddress: "",
      },
      // 表单效验规则
      rulesaddr: {
        takeOverUser: [
          { required: true, message: "请输入收件人", trigger: "blur" },
        ],
        takeOverMobile: [
          {
            required: true,
            pattern: /^[1][0-9]{10}$/,
            message: "请输入有效的手机号",
          },
        ],
        takeOverAddress: [
          { required: true, message: "请输入收货地址", trigger: "blur" },
        ],
      },
    };
  },
  watch: {
    // 获取开始时间和结束时间
    infBox: {
      handler(selectDay) {
        console.log(selectDay, 3333333333333);
        this.addrform = selectDay;
      },
      deep: true, //如果改成监听searchData，然后把这行放开，就可以监听到searchData中任一值
    },
  },
  computed: {},
  created() {},
  methods: {
    cancel(){
        this.$emit('FnchangeAddr')
    },
    submitAddr(ele) {
      this.$refs[ele].validate(async (valid) => {
        if (valid) {

          invoicing(this.addrform)
            .then((res) => {
              this.$message({
                message: res.data.msg,
                type: "success",
              });
              this.$emit('FnchangeAddr',true)
             })
            .catch(() => {});
          
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-button.is-plain:focus, .el-button.is-plain:hover{
  border: 1px solid #25a2ab;
  color: #25a2ab;
}
.forms {
  width: 500px;
  margin: 50px 0;
}
.changeAddr {
}
</style>